<?php
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
///关于充值，提现统计，手续费
$sfwhere      = "";
if($startdate!="" && $enddate!=""){
  $sfwhere    = " and checktime>='$startdate' and  checktime<='$enddate'";  
} 
$rows = $dbselect->GetRows("select cid,SUBSTR(checktime,1,10 ) as checktime,
sum(if(aptype=4,money,0)) as 线下充值,sum(if(aptype=4,1,0)) as 线下充值次数,sum(if(aptype=4,fee,0)) as 线下充值手续费,
sum(if(aptype=5,money,0)) as 转可提,sum(if(aptype=5,1,0)) as 转可提次数,sum(if(aptype=5,fee,0)) as 转可提手续费,
sum(if(aptype=6,money,0)) as 提现,sum(if(aptype=6,1,0)) as 提现次数,sum(if(aptype=6,fee,0)) as 提现手续费,
sum(if(aptype=7 and csid2>0,money,0)) as 线上充值,sum(if(aptype=7 and csid2>0,1,0)) as 线上充值次数,sum(if(aptype=7 and csid2>0,fee,0)) as 线上充值手续费,
sum(if(aptype=7 and csid2=0,money,0)) as 客服充值,sum(if(aptype=7 and csid2=0,1,0)) as 客服次数,sum(if(aptype=7 and csid2=0,fee,0)) as 客服手续费,
sum(if(aptype=11,money,0)) as 代扣充值,sum(if(aptype=11,1,0)) as 代扣充值次数,sum(if(aptype=7,fee,0)) as 代扣手续费
from 04a_3applyqueue where 
aptype in ( 4,5,6,7,11) and status=3 $sfwhere
group by cid,SUBSTR(checktime, 1, 10 )");
foreach($rows as &$row){
    $cid    = $row['cid'];
    $ctime  = strtotime($row['checktime']);
    $Y      = date("Y", $ctime);
    $M      = date("n", $ctime);
    $D      = date("j", $ctime); 
    $c_c_xx = $row['线下充值次数'];
    $c_c_zkt= $row['转可提次数'];
    $c_c_tx = $row['提现次数'];
    $c_c_xs = $row['线上充值次数'];
    $c_c_kf = $row['客服次数'];
    $c_c_dk = $row['代扣充值次数'];
 
    ///对于标一些特殊的资金变动的特殊统计 
    if($c_c_xx>0){
        CTLog::G()->doctAndDayReal($c_c_xx.",rp_{$Y}{$m}_st01",1,"tot_cashbnet",$row['线下充值'],$Y,$M,$D); 
        CTLog::G()->doctAndDayReal($c_c_xx.",rp_{$Y}{$m}_cid",$cid,"tot_cashbnet",$row['线下充值'],$Y,$M,$D);
        if($row['线下充值手续费']>0){
            CTLog::G()->doctAndDayReal($c_c_xx.",rp_{$Y}{$m}_st01",1,"tot_cashbnet_fee",$row['线下充值手续费'],$Y,$M,$D);  
            CTLog::G()->doctAndDayReal($c_c_xx.",rp_{$Y}{$m}_cid",$cid,"tot_cashbnet_fee",$row['线下充值手续费'],$Y,$M,$D);
        }
    }
    if($c_c_zkt>0){
        CTLog::G()->doctAndDayReal($c_c_zkt.",rp_{$Y}{$m}_st01",1,"tot_zhuanketi",$row['转可提'],$Y,$M,$D);  
        CTLog::G()->doctAndDayReal($c_c_zkt.",rp_{$Y}{$m}_cid",$cid,"tot_zhuanketi",$row['转可提'],$Y,$M,$D);
        if($row['转可提手续费']>0){
            CTLog::G()->doctAndDayReal($c_c_zkt.",rp_{$Y}{$m}_st01",1,"tot_zhuanketi_fee",$row['转可提手续费'],$Y,$M,$D);  
            CTLog::G()->doctAndDayReal($c_c_zkt.",rp_{$Y}{$m}_cid",$cid,"tot_zhuanketi_fee",$row['转可提手续费'],$Y,$M,$D);
        }
    }
    if($c_c_tx>0){
        CTLog::G()->doctAndDayReal($c_c_tx.",rp_{$Y}{$m}_st01",1,"tot_cashout",$row['提现'],$Y,$M,$D);  
        CTLog::G()->doctAndDayReal($c_c_tx.",rp_{$Y}{$m}_cid",$cid,"tot_cashout",$row['提现'],$Y,$M,$D);
        if($row['提现手续费']>0){
            CTLog::G()->doctAndDayReal($c_c_tx.",rp_{$Y}{$m}_st01",1,"tot_cashout_fee",$row['提现手续费'],$Y,$M,$D);  
            CTLog::G()->doctAndDayReal($c_c_tx.",rp_{$Y}{$m}_cid",$cid,"tot_cashout_fee",$row['提现手续费'],$Y,$M,$D);
        }
    }
    if($c_c_xs>0){
        CTLog::G()->doctAndDayReal($c_c_xs.",rp_{$Y}{$m}_st01",1,"tot_cashnet",$row['线上充值'],$Y,$M,$D);  
        CTLog::G()->doctAndDayReal($c_c_xs.",rp_{$Y}{$m}_cid",$cid,"tot_cashnet",$row['线上充值'],$Y,$M,$D);
        if($row['线上充值手续费']>0){
            CTLog::G()->doctAndDayReal($c_c_xs.",rp_{$Y}{$m}_st01",1,"tot_cashnet_fee",$row['线上充值手续费'],$Y,$M,$D);  
            CTLog::G()->doctAndDayReal($c_c_xs.",rp_{$Y}{$m}_cid",$cid,"tot_cashnet_fee",$row['线上充值手续费'],$Y,$M,$D);
        }
    }
    if($c_c_kf>0){
        CTLog::G()->doctAndDayReal($c_c_kf.",rp_{$Y}{$m}_st01",1,"tot_cashin",$row['客服充值'],$Y,$M,$D); 
        CTLog::G()->doctAndDayReal($c_c_kf.",rp_{$Y}{$m}_cid",$cid,"tot_cashin",$row['客服充值'],$Y,$M,$D);
        if($row['客服手续费']>0){
            CTLog::G()->doctAndDayReal($c_c_kf.",rp_{$Y}{$m}_st01",1,"tot_cashin_fee",$row['客服手续费'],$Y,$M,$D);  
            CTLog::G()->doctAndDayReal($c_c_kf.",rp_{$Y}{$m}_cid",$cid,"tot_cashin_fee",$row['客服手续费'],$Y,$M,$D);
        }
    }
    if($c_c_dk>0){
        CTLog::G()->doctAndDayReal($c_c_dk.",rp_{$Y}{$m}_st01",1,"tot_cashindk",$row['代扣充值'],$Y,$M,$D);  
        CTLog::G()->doctAndDayReal($c_c_dk.",rp_{$Y}{$m}_cid",$cid,"tot_cashindk",$row['代扣充值'],$Y,$M,$D);
        if($row['代扣手续费']>0){
            CTLog::G()->doctAndDayReal($c_c_kf.",rp_{$Y}{$m}_st01",1,"tot_cashindk_fee",$row['客服手续费'],$Y,$M,$D);  
            CTLog::G()->doctAndDayReal($c_c_kf.",rp_{$Y}{$m}_cid",$cid,"tot_cashindk_fee",$row['客服手续费'],$Y,$M,$D);
        }
    }
}